/*
 * StaticChat.java
 *
 * Created on 2007年5月30日, 上午9:49
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.ecomm.chat.manager;

import com.pphome.orgmodel.manager.UserManager;
import javax.servlet.*;
import javax.servlet.http.*;
import com.ecomm.util.DB;
import com.ecomm.util.DBFactory;

/**
 *在启动系统时将聊天那边的状态清空为默认的状态
 *主要清空3个表  CHAT_LISTEN CHAT_GROUP CHAT_USERINFO
 * <p>Title: 易讯聊天系统</p>
 * <p>Description:
 *  易讯聊天系统
 * </p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: 联合易讯 </p>
 * @author <font color='blue'>pijunliang</font> &nbsp&nbsp<a href="mailto:pijunliang@hotmail.com">pijunliang@hotmail.com</a>
 * @version 1.0
 * @since 2007年5月30日, 上午9:49
 */
public class ChatListener extends HttpServlet implements ServletContextListener {
  /**
   *
   * @param sce ServletContextEvent 环境参数
   */
  public void contextInitialized(ServletContextEvent sce) {
    System.out.println("..loading....清空用户状态！time:"+com.ecomm.util.DateUtils.getCurrTime());
    this.updatestate();
  }
  
  /**
   *
   * @param sce ServletContextEvent 环境参数
   */
  public void contextDestroyed(ServletContextEvent sce) {
    
    System.out.println("......."+com.ecomm.util.DateUtils.getCurrTime()+".......");
  }
  /**
   *在启动系统时将聊天那边的状态清空为默认的状态
   *主要清空3个表  CHAT_LISTEN CHAT_GROUP CHAT_USERINFO
   */
  public static void updatestate(){
    
    String sql_chatListen ="UPDATE CHAT_LISTEN SET JOINPEOPLE = '' WHERE (JOINPEOPLE <> '')";
    String sql_chatGroup="UPDATE CHAT_GROUP SET JOINPEOPLE = '' WHERE (JOINPEOPLE <> '')";
    String sql_chatuserinfo="UPDATE CHAT_USERINFO SET ONLINESTATE = '0' WHERE (ONLINESTATE <> '0')";
    UserManager.getInstance().initUserInfo();
    DB db=null;
    try {
      if(db ==null)
        db= DBFactory.getDBInstance();
      db.executeUpdate(sql_chatListen);
      db.executeUpdate(sql_chatGroup);
      db.executeUpdate(sql_chatuserinfo);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if(db!=null)
        db.close();
    }
  }
}

